package com.common;

import com.Config;

import java.util.*;

public class MyProperties extends Properties {

	private static final long serialVersionUID = -8768311861084082551L;
	private final LinkedHashSet<Object> keys = new LinkedHashSet<>();

	public MyProperties() {
		super();
	}

	public MyProperties(Config config) {
		this.setProperty("WORKSPACEPROPATH",config.getWORKSPACEPROPATH());
		this.setProperty("SRCPATH",config.getSRCPATH());
		this.setProperty("CONTROLLER_PACKAGE",config.getCONTROLLER_PACKAGE());
		this.setProperty("SERVICE_PACKAGE",config.getSERVICE_PACKAGE());
		this.setProperty("SERVICEIMPL_PACKAGE",config.getSERVICEIMPL_PACKAGE());
		this.setProperty("DAO_PACKAGE",config.getDAO_PACKAGE());
		this.setProperty("MAPPING_PACKAGE",config.getMAPPING_PACKAGE());
		this.setProperty("WEBSRCPATH",config.getWEBSRCPATH());
		this.setProperty("JSSRCPATH",config.getJSSRCPATH());
		this.setProperty("JSP_PACKAGE",config.getJSP_PACKAGE());
	}

	@Override
	public Enumeration<Object> keys() {
		return Collections.enumeration(keys);
	}

	@Override
	public Object put(Object key, Object value) {
		keys.add(key);
		return super.put(key, value);
	}

	@Override
	public Set<String> stringPropertyNames() {
		Set<String> set = new LinkedHashSet<>();
		for (Object key : this.keys) {
			set.add((String) key);
		}
		return set;
	}

	@Override
	public Set<Object> keySet() {
		return keys;
	}

	public Object remove(Object o) {
		keys.remove(o);
		return super.remove(o);
	}

	@Override
	public Enumeration<?> propertyNames() {
		return Collections.enumeration(keys);
	}

}
